package com.wm.wmim.connect.center.factory;


import com.wm.wmim.connect.ws.api.rpc.PushWsMessageRpcService;
import org.apache.dubbo.config.ReferenceConfig;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author weiming
 * @date 2024/12/25 15:07
 * @description
 */
public class RouteRpcServiceFactory {

    private static Map<String, PushWsMessageRpcService> pushRpcServiceMap = new ConcurrentHashMap<>();

    // TODO 加锁

    public static PushWsMessageRpcService getPushWsMessageRpcService(String path) {
        synchronized (pushRpcServiceMap){
            PushWsMessageRpcService pushWsMessageRpcService = pushRpcServiceMap.get(path);
            if (pushWsMessageRpcService != null) {
                return pushWsMessageRpcService;
            }
            ReferenceConfig<PushWsMessageRpcService> rf = new ReferenceConfig<PushWsMessageRpcService>();
            rf.setInterface(PushWsMessageRpcService.class);
            rf.setVersion("1.0.0");
            rf.setCheck(false);
            rf.setUrl("dubbo://" + path);
            pushWsMessageRpcService = rf.get();
            pushRpcServiceMap.put(path, pushWsMessageRpcService);
            return pushWsMessageRpcService;
        }
    }

}
